import request from '@/config/axios';

import { i18n } from '@/plugins/vueI18n'
let my18nData = {}

export const loadMy18nData = async () => {
  let langStr = localStorage.lang
  if (!langStr) {
    return {};
  }
  langStr = langStr.replaceAll('\\"', "")
  const lang = JSON.parse(langStr);
  let url = '/magic-api/open/my18n/en'
  if ('zh-CN' == lang.v || 'zh-cn' == lang.v || 'cn' == lang.v) {
    url = '/magic-api/open/my18n/cn'
  }
  my18nData = await request.get({ url })
}

export const my18nGet = (key: string) => {
    let value = my18nData[key]
    console.log('my18nGet 1', key, value)

    if (value) {
      return value;
    }
    value = i18n.global.t(key)
    console.log('my18nGet 2', key , value)
    
  return value;
}
